import {
	mapMutations
} from 'vuex'
export default {
	...mapMutations([
		'upUserList'
	]),
	getPageList() {
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'wechat/getUserList',
			method: 'get',
			params: {
				pageNo: that.page,
				pageSize: that.list_rows,
				keyword: that.keyword,
			},
			success: res => {
				that.loading = false
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					if (that.page === 1) {
						that.list = res.data.rows
					} else {
						that.list = that.list.concat(res.data.rows)
					}
					that.page++
				} else {

				}
			}
		}, false)
	},
	// 检查用户是否已经被选中
	isSelected(user) {
		return this.selectedUsers.some(selectedUser => selectedUser.id === user.id);
	},
	// 更新选中用户的方法
	handleCheckboxChange(user) {
		if (this.isSelected(user)) {
			// 取消选中：从 selectedUsers 中移除该用户
			this.selectedUsers = this.selectedUsers.filter(
				selectedUser => selectedUser.id !== user.id
			);
		} else {
			// 选中：向 selectedUsers 添加该用户
			this.selectedUsers.push({
				id: user.id,
				nickname: user.nickname,
				avatar: user.avatar
			});
		}
		this.upUserList(this.selectedUsers)
	},
	changeKeyword() {
		this.page = 1;
		this.list = []
		this.getPageList()
	},
}